package com.myzl.web.controller.coal;

import com.myzl.coal.domain.HistoryData;
import com.myzl.coal.service.IHistoryDataService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实时数据Controller
 *
 * @author myzl
 * @date 2022-10-31
 */
@RestController
@RequestMapping("/coal/historyData")
public class HistoryDataController extends BaseController
{
    @Autowired
    private IHistoryDataService historyDataService;

    /**
     * 查询实时数据列表
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:list')")
    @GetMapping("/list")
    public TableDataInfo list(HistoryData historyData)
    {
        startPage();
        List<HistoryData> list = historyDataService.selectHistoryDataList(historyData);
        return getDataTable(list);
    }

    /**
     * 导出实时数据列表
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:export')")
    @Log(title = "实时数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HistoryData historyData)
    {
        List<HistoryData> list = historyDataService.selectHistoryDataList(historyData);
        ExcelUtil<HistoryData> util = new ExcelUtil<HistoryData>(HistoryData.class);
        util.exportExcel(response, list, "实时数据数据");
    }

    /**
     * 获取实时数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(historyDataService.selectHistoryDataById(id));
    }

    /**
     * 新增实时数据
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:add')")
    @Log(title = "实时数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HistoryData historyData)
    {
        return toAjax(historyDataService.insertHistoryData(historyData));
    }

    /**
     * 修改实时数据
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:edit')")
    @Log(title = "实时数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HistoryData historyData)
    {
        return toAjax(historyDataService.updateHistoryData(historyData));
    }

    /**
     * 删除实时数据
     */
    @PreAuthorize("@ss.hasPermi('coal:historyData:remove')")
    @Log(title = "实时数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(historyDataService.deleteHistoryDataByIds(ids));
    }
}
